<?php
namespace api;
use controller;

use model\tool\imageModel;
use model\moduleModel;
use model\goodsModel;

class recommend extends controller{

    public function index(){

        $recommend = moduleModel::getRecommend();

        if( !empty($recommend) && !empty($recommend['settings'])  ){
            $settings = json_decode( $recommend['settings'], true );
            $goods_list = !empty($settings['goods_list'])? $settings['goods_list']: [];

            $recommend['goods_list'] = [];
            foreach ( $goods_list as $goods_id ){

                $goods = goodsModel::detail( $goods_id );

                if( !empty($goods['image'] ) ){

                    $goods['image'] = imageModel::resize( $goods['image'], '300', '300' );

                }else{
                    $goods['image'] = WEB_URL . '/image/no_image.png';
                }

                if( !empty( $goods ) ){
                    $recommend['goods_list'][] = $goods;
                }

            }
        }

        $recommend['goods_list'] = !empty( $recommend['goods_list'] ) ? $recommend['goods_list'] : [];
        echo json_encode( $recommend );

    }

}